using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.IO;using System.Collections;namespace bofangqi{ public partial class Form1 : Form { ListSong lst = new ListSong(); //public Form1 myform; public Form1() { lst.mainform = this; InitializeComponent(); this.skinChang.SkinFile = "DiamondGreen.ssk"; } private void Form1_Load(object sender, EventArgs e) { this.Size = new Size(484, 402); Point p = new Point(120, 80); this.DesktopLocation = p; this.lst.Show(); } #region 定义数组 public ArrayList MyArrylist = new ArrayList(); public ArrayList List = new ArrayList(); #endregion #region 添加歌曲 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { add(); if (AxWmp.playState != WMPLib.WMPPlayState.wmppsPlaying) { this.PlaySong(); } } #endregion #region 基本方法 //添加方法 public void add() { this.odlgFile.Filter = "媒体文件|*.mp3;*.wav;*.wma;*.mid;*.avi;*.mpg;*.asf;*.wmv;*.rmvb"; if (odlgFile.ShowDialog() == DialogResult.OK) { for (int i = 0, j = lst.lstSong.Items.Count 1; i < odlgFile.FileNames.Length; i , j ) { if (!List.Contains(this.odlgFile.FileNames[i].Split('\\')[this.odlgFile.FileNames[i].Split('\\').Length - 1])) this.MyArrylist.Add(this.odlgFile.FileNames[i]); string list = this.odlgFile.FileNames[i].Split('\\')[this.odlgFile.FileNames[i].Split('\\').Length - 1]; string SongName = j.ToString() "." this.odlgFile.FileNames[i].Split('\\')[this.odlgFile.FileNames[i].Split('\\').Length - 1]; List.Add(list); lst.lstSong.Items.Add(SongName); } } } //删除歌曲 public void Delete() { if (lst.lstSong.SelectedIndex != -1) { List.RemoveAt(lst.lstSong.SelectedIndex); MyArrylist.RemoveAt(lst.lstSong.SelectedIndex); lst.lstSong.Items.RemoveAt(lst.lstSong.SelectedIndex); lst.lstSong.Items.Clear(); for (int i = 0; i < List.Count; i ) { int index = i 1; string name = index "." List[i].ToString(); lst.lstSong.Items.Insert(i, name); } this.StopSong(); } } //清空歌曲 public void Clear() { lst.lstSong.Items.Clear(); this.StopSong(); this.MyArrylist.Clear(); this.List.Clear(); } #endregion #region 播放状态 void RePlayState() { ShowSongInfo(); //是否是播放状态 if (AxWmp.playState == WMPLib.WMPPlayState.wmppsPlaying) { this.stbInfo.Text = "正在播放"; } if (AxWmp.playState == WMPLib.WMPPlayState.wmppsPaused) { this.stbInfo.Text = "暂停"; } //是否是停止状态、 if (AxWmp.playState == WMPLib.WMPPlayState.wmppsStopped || AxWmp.playState == WMPLib.WMPPlayState.wmppsUndefined) { this.InfoClear(); if (!mIOneMode.Checked && !mIlistMode.Checked) NextSong(); { if (lst.lstSong.Items.Count - 1 > lst.lstSong.SelectedIndex && lst.lstSong.SelectedIndex != -1) { lst.lstSong.SelectedIndex = lst.lstSong.SelectedIndex 1; PlaySong(); } else if (lst.lstSong.Items.Count > 0) { lst.lstSong.SelectedIndex = 0; PlaySong(); } } if(mINone.Checked) { Random r = new Random(); int music = r.Next(1,lst. lstSong.Items.Count); lst.lstSong.SelectedIndex = music; PlaySong(); } if (lst.lstSong.SelectedIndex == -1) this.timerPlay.Enabled = false; } } #endregion #region 基本控制 //播放 public void PlaySong() { //开始检测播放状态,Timer启动。 this.timerPlay.Enabled = true; //检查是否选中 if (lst.lstSong.SelectedIndex != -1) { this.AxWmp.URL = this.MyArrylist[lst.lstSong.SelectedIndex].ToString(); this.Text = lst.lstSong.Items[lst.lstSong.SelectedIndex].ToString(); } //检查是否有曲目 else if (lst.lstSong.Items.Count > 0) { lst.lstSong.SelectedIndex = 0; this.AxWmp.URL = this.MyArrylist[lst.lstSong.SelectedIndex].ToString(); this.Text = lst.lstSong.Items[lst.lstSong.SelectedIndex].ToString(); } } //上曲 public void BackSong() { //检测是否是第一首 if (lst.lstSong.SelectedIndex > 0) { lst.lstSong.SelectedIndex = lst.lstSong.SelectedIndex - 1; PlaySong(); } } //下曲 public void NextSong() { if (lst.lstSong.Items.Count - 1 > lst.lstSong.SelectedIndex &&lst. lstSong.SelectedIndex != 1) { lst.lstSong.SelectedIndex = lst.lstSong.SelectedIndex 1; PlaySong(); } //检测是否存在歌曲 else if (lst.lstSong.Items.Count > 0) { lst.lstSong.SelectedIndex = 0; PlaySong(); } } //停止 public void StopSong() { //停止检测播放状态 this.timerPlay.Enabled = false; this.AxWmp.Ctlcontrols.stop(); InfoClear(); } //暂停 public void PauseSong() { if (AxWmp.playState == WMPLib.WMPPlayState.wmppsPaused) { this.AxWmp.Ctlcontrols.play(); } else { this.AxWmp.Ctlcontrols.pause(); } } //信息重置 void InfoClear() { this.txtName.Text = "欢迎使用"; this.tkbMove.Maximum = 0; this.tkbMove.Value = 0; this.txtTime.Text = "00:00|00:00"; this.stbInfo.Text = "就绪"; } #endregion #region 获取媒体及时信息 void ShowSongInfo() { //wmppsStopped 停止状态,wmppsUndefined 位置状态 if (this.AxWmp.playState != WMPLib.WMPPlayState.wmppsStopped && this.AxWmp.playState != WMPLib.WMPPlayState.wmppsUndefined) { //获取名称 //this.txtName.Text = this.AxWmp.currentMedia.name; //媒体总长度 this.tkbMove.Maximum = (int)this.AxWmp.currentMedia.duration; //媒体当前长度 this.tkbMove.Value = (int)this.AxWmp.Ctlcontrols.currentPosition; //显示当前时间 this.txtTime.Text = this.AxWmp.Ctlcontrols.currentPositionString '|' this.AxWmp.currentMedia.durationString; ; } } #endregion #region 歌曲功能控制 //播放按钮 private void btnPlay_Click(object sender, EventArgs e) { PlaySong(); } //停止按钮 private void btnStop_Click(object sender, EventArgs e) { this.timerPlay.Enabled = false; this.AxWmp.Ctlcontrols.stop(); InfoClear(); } //暂停按钮 private void btnPause_Click(object sender, EventArgs e) { if (AxWmp.playState == WMPLib.WMPPlayState.wmppsPaused) { this.AxWmp.Ctlcontrols.play(); } else { this.AxWmp.Ctlcontrols.pause(); } } //下一曲按钮 private void btnNext_Click(object sender, EventArgs e) { if ( mINone.Checked ) { Random r = new Random(); int music = r.Next(1,lst. lstSong.Items.Count); lst.lstSong.SelectedIndex = music; PlaySong(); } if (lst.lstSong.Items.Count - 1 > lst.lstSong.SelectedIndex && lst.lstSong.SelectedIndex != -1) { lst.lstSong.SelectedIndex =lst. lstSong.SelectedIndex 1; PlaySong(); } } //上一曲按钮 private void btnBack_Click(object sender, EventArgs e) { if (lst.lstSong.SelectedIndex > 0) { lst.lstSong.SelectedIndex = lst.lstSong.SelectedIndex - 1; PlaySong(); } } //快进按钮 private void btnFast_Click(object sender, EventArgs e) { AxWmp.Ctlcontrols.currentPosition = AxWmp.Ctlcontrols.currentPosition 10; } //快退按钮 private void button2_Click(object sender, EventArgs e) { AxWmp.Ctlcontrols.currentPosition = AxWmp.Ctlcontrols.currentPosition - 10; } //每秒刷新信息,TIMER 事件 private void timerPlay_Tick_1(object sender, EventArgs e) { showlrc(); RePlayState(); } //设置当前进度 private void tkbMove_Scroll_1(object sender, EventArgs e) { this.AxWmp.Ctlcontrols.currentPosition = (double)this.tkbMove.Value; } #endregion #region 模式控制 //播放循环模式代号 ModeNumber=0,1,2 void PlayMode(int ModeNumber) { if (ModeNumber == 0) { this.mIOneMode.Checked = true; this.mIlistMode.Checked = false; this.mINone.Checked = false; this.AxWmp.settings.playCount = 99; } if (ModeNumber == 1) { this.mIOneMode.Checked = false; this.mIlistMode.Checked = true; this.mINone.Checked = false; this.AxWmp.settings.playCount = 1; } if (ModeNumber == 2) { this.mIOneMode.Checked = false; this.mIlistMode.Checked = false; this.mINone.Checked = true; this.AxWmp.settings.playCount = 1; } } //单曲循环 private void mIOneMode_Click(object sender, EventArgs e) { PlayMode(0); } //顺序播放 private void mIlistMode_Click_1(object sender, EventArgs e) { PlayMode(1); } //随机播放 private void mINone_Click_1(object sender, EventArgs e) { PlayMode(2); } #endregion #region 声音控制 //静音设置 private void chkJy_CheckedChanged(object sender, EventArgs e) { if (this.chkJy.Checked == true) { this.AxWmp.settings.volume = 0; this.tkbVol.Enabled = false; } if (this.chkJy.Checked == false) { this.tkbVol.Enabled = true; this.AxWmp.settings.volume = this.tkbVol.Value; } } //音量 private void tkbVol_Scroll(object sender, EventArgs e) { AxWmp.settings.volume = tkbVol.Value; } #endregion #region 皮肤设置 private void skinOne_Click(object sender, EventArgs e) { this.skinOne.Checked = true; this.skinTwo.Checked = false; this.skinThree.Checked = false; this.skinFour.Checked = false; skinChang.SkinFile = AppDomain.CurrentDomain.BaseDirectory "SportsOrange.ssk"; } private void skinTwo_Click_1(object sender, EventArgs e) { this.skinOne.Checked = false; this.skinTwo.Checked = true; this.skinThree.Checked = false; this.skinFour.Checked = false; skinChang.SkinFile = AppDomain.CurrentDomain.BaseDirectory "MP10.ssk"; } private void skinThree_Click_1(object sender, EventArgs e) { this.skinOne.Checked = false; this.skinTwo.Checked = false; this.skinThree.Checked = true; this.skinFour.Checked = false; skinChang.SkinFile = AppDomain.CurrentDomain.BaseDirectory "SportsCyan.ssk"; } private void skinFour_Click_1(object sender, EventArgs e) { this.skinOne.Checked = false; this.skinTwo.Checked = false; this.skinThree.Checked = false; this.skinFour.Checked = true; skinChang.SkinFile = AppDomain.CurrentDomain.BaseDirectory "SilverColor2.ssk"; } #endregion #region 全屏功能 //双击鼠标实现全屏播放 private void AxWmp_DoubleClickEvent_1(object sender, AxWMPLib._WMPOCXEvents_DoubleClickEvent e) { this.AxWmp.fullScreen = true; } //单击鼠标退出全屏 private void AxWmp_ClickEvent(object sender, AxWMPLib._WMPOCXEvents_ClickEvent e) { this.AxWmp.fullScreen = false; } private void 全屏ToolStripMenuItem_Click(object sender, EventArgs e) { this.AxWmp.fullScreen = true; } #endregion # region 显示歌词 void showlrc() //歌词显示函数 { //获取当前歌曲播放时间 string time = this.AxWmp.Ctlcontrols.currentPositionString; //获取当前歌曲在列表中的索引号 int n = MyArrylist.IndexOf(AxWmp.URL.ToString()); if (n >= 0) { //得到当前歌曲名 string strlrc = MyArrylist[n].ToString().Split('.')[0] ".lrc"; if (!File.Exists(strlrc)) { this.txtName.Text = "歌词不存在"; } else { StreamReader Fil = new StreamReader(strlrc, System.Text.Encoding.Default); string strLine = Fil.ReadLine(); while (strLine != null) { int x = (strLine.IndexOf(time)); if (x != -1) { this.txtName.Text = (strLine.Substring(strLine.LastIndexOf("]") 1, strLine.Length - strLine.LastIndexOf("]") - 1) "\r\n"); } strLine = Fil.ReadLine(); } } } } #endregion #region 同时移动两个窗体 private void Form1_LocationChanged(object sender, EventArgs e) { lst.Location = new System.Drawing.Point(this.Location.X, this.Location.Y this.Height); } #endregion #region 隐藏列表框 private void chkY_CheckedChanged(object sender, EventArgs e) { if (this.chkY.Checked == true) { lst.Hide(); } else { lst.Show(); } } #endregion #region 添加文件夹 public void 添加文件夹ToolStripMenuItem_Click(object sender, EventArgs e) { FolderBrowserDialog Fdialog = new FolderBrowserDialog(); //FolderBrowserDialog Fdialog = new FolderBrowserDialog(); if (Fdialog.ShowDialog() == DialogResult.OK) { string path = Fdialog.SelectedPath; //File.WriteAllText("LoadMusic.txt", path); foreach (string name in Directory.GetFiles(path)) { FileInfo fileinfo = new FileInfo(name); if (fileinfo.Extension == " .mp3" || fileinfo.Extension == " .wav" || fileinfo.Extension == ".wma" || fileinfo.Extension == ".mid" || fileinfo.Extension == ".avi" || fileinfo.Extension == ".mpgv" || fileinfo.Extension == ".wmv" || fileinfo.Extension == ".rmvb") { int i; for (i = 0; i < lst.lstSong.Items.Count; i ) { if (fileinfo.Name == lst.lstSong.Items[i].ToString()) break; } if (i == lst.lstSong.Items.Count) { lst.lstSong.Items.Add(i " " fileinfo.Name); AxWmp.currentPlaylist.insertItem(AxWmp.currentPlaylist.count, AxWmp.newMedia(i " " fileinfo.Name)); } } } } //if (this.Fdialog.ShowDialog() == DialogResult.OK) //{ // string path = this.Fdialog.SelectedPath; // DirectoryInfo dir = new DirectoryInfo(path); // foreach (FileInfo f in dir.GetFiles("*.mp3 ")) // { // this.lst.lstSong.Items.Add(f.FullName); // } // foreach (FileInfo f in dir.GetFiles("*.mid ")) // { // this.lst.lstSong.Items.Add(f.FullName); // } // foreach (FileInfo f in dir.GetFiles("*.wmv ")) // { // this.lst.lstSong.Items.Add(f.FullName); // } //} } #endregion private void 迷你ToolStripMenuItem_Click(object sender, EventArgs e) { this.menuStrip1.Hide(); this.tkbMove.Hide(); this.tkbVol.Hide(); this.statusStrip1.Hide(); this.lst.Hide(); this.btnShow.Hide(); this.btnFast.Hide(); this.chkJy.Hide(); this.chkY.Hide(); //this.Height = 80; //this.Width = 390; this.AxWmp.Size = new System.Drawing.Size(80, 20); this.AxWmp.Location = new System.Drawing.Point(220, 10); this.btnPlay.Location = new System.Drawing.Point(7, 10); this.btnPause.Location = new System.Drawing.Point(50, 10); this.btnStop.Location = new System.Drawing.Point(93, 10); this.btnBack.Location = new System.Drawing.Point(136, 10); this.btnNext.Location = new System.Drawing.Point(179, 10); this.txtName.Size = new System.Drawing.Size(130, 20); this.txtName.Location = new System.Drawing.Point(305, 10); this.txtTime.Size = new System.Drawing.Size(80, 15); this.txtTime.Location = new System.Drawing.Point(437, 10); this.Size = new System.Drawing.Size(530,80); this.Location = new System.Drawing.Point(120, 0); } private void Form1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Link; else e.Effect = DragDropEffects.None; } private void Form1_DragDrop(object sender, DragEventArgs e) { int n = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).ToString().Length; for (int i = 0, j = lst.lstSong.Items.Count 1; i < n; i ) { this.AxWmp.URL = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(i).ToString(); string songname = this.AxWmp.URL.Split('\\')[this.AxWmp.URL.Split('\\').Length - 1]; int l =lst.lstSong.Items.Count 1; lst.lstSong.Items.Add((l ).ToString() "." songname); this.MyArrylist.Add(this.AxWmp.URL); this.List.Add((l ).ToString() "." songname); } } //Form2 interSong = new Form2(); //private void 网络音乐ToolStripMenuItem_Click(object sender, EventArgs e) //{ // interSong.Show(); // //interSong.FormClosed =this.interSong.Dispose(); //} }}
下载C# 音乐播放器源码下载(支持换肤、歌词同步显示、快进、随机播放等)用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论